/* 717. 1比特与2比特字符 */
/**
 * @param {number[]} bits
 * @return {boolean}
 */
var isOneBitCharacter = function (bits) {
    if (bits.length === 1) return true
    for (let i = 0; i < bits.length; i++) {
        if (!bits[i]) {
            if (i === bits.length - 1) return true
            continue
        }
        i++
    }
    return false
};
/* 正序遍历 */
var isOneBitCharacter = function (bits) {
    let i = 0; n = bits.length
    /* 
        如果遇到了第一种字符 直接+1 遇到第二种字符直接+2
    */
    while (i < n - 1) {
        i += bits[i] + 1
    }
    return i === n - 1
}
/* 倒序遍历 */
var isOneBitCharacter = function (bits) {
    const n = bits.length
    let i = n - 2
    while (i >= 0 && bits[i]) {
        i--
    }

    return (n - i) % 2 === 0
}
const result = isOneBitCharacter([1, 1, 1, 0])
console.log('result :>>', result);